<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Todo List</title>
  <style>
    body {
      font-family: Arial, sans-serif;
    }

    h1 {
      text-align: center;
    }

    input[type="text"] {
      padding: 8px;
      margin-right: 10px;
    }

    button {
      padding: 8px 15px;
      cursor: pointer;
    }

    ul {
      list-style-type: none;
      padding: 0;
    }

    li {
      margin: 10px 0;
      display: flex;
      justify-content: space-between;
      align-items: center;
    }

    li button {
      background-color: #ff6347;
      color: white;
      border: none;
      padding: 5px 10px;
      border-radius: 3px;
    }
  </style>
</head>

<body>
  <h1>Todo List</h1>
  <input type="text" id="taskInput" placeholder="输入任务">
  <button onclick="addTask()">添加任务</button>
  <ul id="taskList"></ul>

  <script>
    function addTask() {
      const taskInput = document.getElementById('taskInput');
      const taskText = taskInput.value.trim();
      if (taskText === "") return;

      const taskList = document.getElementById('taskList');
      const li = document.createElement('li');
      li.textContent = taskText;

      const deleteButton = document.createElement('button');
      deleteButton.textContent = "删除";
      deleteButton.onclick = function () {
        taskList.removeChild(li);
      };

      li.appendChild(deleteButton);
      taskList.appendChild(li);

      taskInput.value = "";
    }
  </script>
</body>

</html>